package work812;

import java.io.File;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class work7 {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Map<String,Integer>map = new HashMap<>();
    System.out.println("请输入文件夹路径：");
    String path = sc.next();
    File file = new File(path);
    File[] files = file.listFiles();
    Integer value = 1;
    for (int i = 0; i < files.length; i++) {
      if (files[i].isFile()){
        String name = files[i].getName();
        String type = name.substring(name.lastIndexOf(".")+1,name.length());
        if (map.get(type)!= null){
           value = value + 1;
        }
        map.put(type,value);
      }
    }
    Set<Map.Entry<String,Integer>> entries = map.entrySet();
    for (Map.Entry<String, Integer> entry : entries) {
      String key = entry.getKey();
      Integer values = entry.getValue();
      System.out.println(key+"类型的文件共有"+values+"个");
    }
    Set<String> keys = map.keySet();
    for (String key : keys) {
      Integer values = map.get(key);
      System.out.println(key+"类型的文件共有"+values+"个");
    }

  }
}
